#!/bin/bash
# 定义一个数组来存储节点ID
declare -a node_ids=(node101 node102)
opt=$1
shift
new_node_ids=("$@")
# 遍历传入的节点ID
for node_id in "${new_node_ids[@]}"; do
    # 检查节点ID是否已经在数组中
    if [[ ! "${node_ids[*]}" =~ ${node_id} ]]; then
        # 如果不在数组中，则添加
        node_ids+=("$node_id")
    fi
done

case $opt in
"start"){
        for i in "${node_ids[@]}"
        do
                echo " --------启动 $i 采集flume-------"
                ssh $i "nohup $FLUME_HOME/bin/flume-ng agent -n a1 -c $FLUME_HOME/conf/ -f $FLUME_HOME/job/file_to_kafka.conf >/dev/null 2>&1 &"
        done
};;
"stop"){
        for i in "${node_ids[@]}"
        do
                echo " --------停止 $i 采集flume-------"
                ssh $i "ps -ef | grep file_to_kafka | grep -v grep |awk  '{print \$2}' | xargs -n1 kill -9 "
        done

};;
esac

